package com.navi.heartbeat.util;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import java.beans.PropertyVetoException;
import org.apache.commons.dbutils.QueryRunner;

/**
 * JdbcUtils
 *
 * @author Matthew
 * @date 2018-07-04
 */
public class JdbcUtils {

  static ComboPooledDataSource qmsGpPool;
  static ComboPooledDataSource qmsMysq1lPool;
  static ComboPooledDataSource mpsMysqlPool;
  static ComboPooledDataSource dpsMysqlPool;
  static ComboPooledDataSource biOraclePool;

  static {

    try {
      qmsMysq1lPool = new ComboPooledDataSource();
      qmsMysq1lPool.setInitialPoolSize(3);
      qmsMysq1lPool.setMinPoolSize(2);
      qmsMysq1lPool.setMaxPoolSize(5);
      qmsMysq1lPool.setUser("root");
      qmsMysq1lPool.setPassword("chot123");
      qmsMysq1lPool.setDriverClass("com.mysql.jdbc.Driver");
      qmsMysq1lPool.setJdbcUrl("jdbc:mysql://10.50.10.180:3306/ch_qms");
    } catch (PropertyVetoException e) {
      e.printStackTrace();
    }

    try {
      qmsGpPool = new ComboPooledDataSource();
      qmsGpPool.setInitialPoolSize(2);
      qmsGpPool.setMinPoolSize(1);
      qmsGpPool.setMaxPoolSize(3);
      qmsGpPool.setUser("etl");
      qmsGpPool.setPassword("navietl");
      qmsGpPool.setDriverClass("org.postgresql.Driver");
      qmsGpPool.setJdbcUrl("jdbc:postgresql://10.50.10.169:5432/qmsprd");
    } catch (PropertyVetoException e) {
      e.printStackTrace();
    }

    try {
      dpsMysqlPool = new ComboPooledDataSource();
      dpsMysqlPool.setInitialPoolSize(3);
      dpsMysqlPool.setMinPoolSize(2);
      dpsMysqlPool.setMaxPoolSize(5);
      dpsMysqlPool.setDriverClass("com.mysql.jdbc.Driver");
      dpsMysqlPool.setUser("root");
      dpsMysqlPool.setPassword("chot123");
      dpsMysqlPool.setJdbcUrl("jdbc:mysql://10.56.200.91:3306/chot_dps?characterEncoding=utf-8&zeroDateTimeBehavior="
          + "convertToNull&transformedBitIsBoolean=true");
    } catch (PropertyVetoException e) {
      e.printStackTrace();
    }

    try {
      mpsMysqlPool = new ComboPooledDataSource();
      mpsMysqlPool.setInitialPoolSize(3);
      mpsMysqlPool.setMinPoolSize(2);
      mpsMysqlPool.setMaxPoolSize(5);
      mpsMysqlPool.setDriverClass("com.mysql.jdbc.Driver");

      mpsMysqlPool.setUser("root");
      mpsMysqlPool.setPassword("chot123");
      mpsMysqlPool.setJdbcUrl("jdbc:mysql://10.56.200.91:3306/chot_mps?characterEncoding=utf-8&zeroDateTimeBehavior="
          + "convertToNull&transformedBitIsBoolean=true");
    } catch (PropertyVetoException e) {
      e.printStackTrace();
    }

    try {
      biOraclePool = new ComboPooledDataSource();
      biOraclePool.setInitialPoolSize(2);
      biOraclePool.setMinPoolSize(1);
      biOraclePool.setMaxPoolSize(5);

      biOraclePool.setUser("edwuser");
      biOraclePool.setPassword("datacvg2018");
      biOraclePool.setDriverClass("oracle.jdbc.driver.OracleDriver");
      biOraclePool.setJdbcUrl("jdbc:oracle:thin:@//10.50.10.40:1521/chotedw");

    } catch (PropertyVetoException e) {
      e.printStackTrace();
    }
  }
  public static QueryRunner getQmsGpRunner() {
    return new QueryRunner(qmsGpPool);
  }
  public static QueryRunner getQmsMysqlRunner() {
    return new QueryRunner(qmsMysq1lPool);
  }
  public static QueryRunner getMpsMysqlRunner() {
    return new QueryRunner(mpsMysqlPool);
  }
  public static QueryRunner getDpsMysqlRunner() {
    return new QueryRunner(dpsMysqlPool);
  }
  public static QueryRunner getBiOracleRunner() {
    return new QueryRunner(biOraclePool);
  }

}
